<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>管理后台-修改任务</title>
    <header th:replace="header::html"/>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <input type="hidden" id="taskId" name="id" th:value="${task.id}" />
                <div class="layui-form-item">
                    <label for="jobName" class="layui-form-label">
                        <span class="x-red">*</span>任务名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="jobName" name="jobName" th:value="${task.jobName}" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="description" class="layui-form-label">任务描述</label>
                    <div class="layui-input-inline">
                        <input type="text" id="description" name="description" th:value="${task.description}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="jobGroup" class="layui-form-label">任务分组</label>
                    <div class="layui-input-inline">
                        <input type="text" id="jobGroup" name="jobGroup" th:value="${task.jobGroup}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="beanClass" class="layui-form-label">
                        <span class="x-red">*</span>任务类
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="beanClass" name="beanClass" th:value="${task.beanClass}" lay-verify="required" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        请输入类的全路径
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="cronExpression" class="layui-form-label">
                        <span class="x-red">*</span>cron表达式
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="cronExpression" name="cronExpression" th:value="${task.cronExpression}" lay-verify="required" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        cron表达式必须正确
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-filter="edit" lay-submit="" permission="sys:task:edit">修改</button>
                        <button class="layui-btn layui-btn-primary" onclick="xadmin.close();">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript">
        layui.use(['form', 'layer'], function () {
            var form = layui.form,
                layer = layui.layer;

            // 权限校验
            checkPermissoin();

            // 自定义验证规则
            form.verify({

            });

            // 监听提交
            form.on('submit(edit)', function (data) {
                // 发异步请求，修改任务
                $.ajax({
                    url: '/task/edit',
                    type: 'PUT',
                    data: data.field,
                    dataType: 'json',
                    beforeSend: function() {
                        layer.load();
                    },
                    success: function (res) {
                        if (res.httpCode != 200 || res.retCode != 0) {
                            layer.alert(res.retMsg);
                        } else {
                            layer.alert("修改成功", {icon: 6}, function () {
                                // 关闭当前frame
                                xadmin.close();
                                // 对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        }
                    }
                });
                layer.closeAll();
                return false;
            });
        });
    </script>
</body>
</html>
